HTTP Cache-Control and Expires
· One min read
-
Cache-Control
overrideExpires
- Ref: RFC 9111
-
Cache-Control
supersedesExpires
-
Cache-Control
offers more flexibility and options thanExpires
-
Cache-Control
use relative amount of time (seconds)Cache-Control: max-age=3600
-
Expires
use date formatExpires: Thu, 01 Dec 1994 16:00:00 GMT
Cache states
Caches have 2 states:
- fresh: if cache age <
max-age
, the cache is valid - stale: if cache age >
max-age
, the cache needs to be validated
Validate cache when reuse
Browser will always validate cache when reuse
- If browser has a fresh cache, it will reuse it and will not send request to server
Cache-Control: no-cache
Disable cache
Browser will not store cache
Cache-Control: no-store
Clear cache
- Pressing Ctrl + F5 in browser will reload current page without using cache
- Most browsers support pressing Ctrl + Shift + Delete to clear cache